<template>
  <div class="app-container">
    <el-form :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      class="form-search"
      label-width="100px">
      <el-form-item :label="$t('payrollO.exchangeName')"
        prop="exchangeName">
        <el-select v-model="queryParams.exchangeId"
          filterable
          remote
          reserve-keyword
          :placeholder="$t('common.placeholderSelect')"
          :remote-method="remoteMethod"
          :loading="exhloading"
          style="width: 240px">
          <el-option v-for="item in exchangeList"
            :key="item.exchangeId"
            :label="item.exchangeName"
            :value="item.exchangeId">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('payrollO.subject')"
        prop="subject">
        <el-input v-model="queryParams.subject"
          :placeholder="$t('common.placeholderContent')"
          clearable
          style="width: 240px"
          maxlength="50"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item :label="$t('payrollO.transStatus')"
        prop="transStatus">
        <el-select v-model="queryParams.transStatus"
          :placeholder="$t('common.placeholderSelect')"
          clearable
          style="width: 240px">
          <el-option v-for="dict in dict.type.trans_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('payrollO.auditStatus')"
        prop="auditStatus">
        <el-select v-model="queryParams.auditStatus"
          :placeholder="$t('common.placeholderSelect')"
          clearable
          style="width: 240px">
          <el-option v-for="dict in dict.type.audit_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('payrollO.status')"
        prop="status">
        <el-select v-model="queryParams.status"
          :placeholder="$t('common.placeholderSelect')"
          clearable
          style="width: 240px">
          <el-option v-for="dict in dict.type.sys_data_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery">{{$t('common.search')}}</el-button>
        <el-button icon="el-icon-refresh"
          size="mini"
          @click="resetQuery">{{$t('common.reset')}}</el-button>
      </el-form-item>
    </el-form>

    <div class="section-box">
      <el-row :gutter="10"
        class="mb8">
        <el-col :span="1.5">
          <el-button type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd">{{$t('common.add')}}</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="success"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleDownload">{{$t('common.template')}}</el-button>
        </el-col>
        <!-- <el-col :span="1.5">
          <el-button type="success"
            plain
            icon="el-icon-edit"
            size="mini"
            :disabled="single"
            @click="handleUpdate">{{$t('common.edit')}}</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete">{{$t('common.delete')}}</el-button>
        </el-col> -->
        <right-toolbar :showSearch.sync="showSearch"
          @queryTable="getList"></right-toolbar>
      </el-row>

      <el-table v-loading="loading"
        :data="batchList">
        <!-- <el-table-column type="selection"
          width="55"
          align="center" /> -->
        <el-table-column :label="$t('payrollO.subject')"
          align="center"
          prop="subject"
          min-width="160"
          show-overflow-tooltip />
        <el-table-column :label="$t('payrollO.exchangeName')"
          align="center"
          prop="exchangeName"
          min-width="160"
          show-overflow-tooltip />
        <el-table-column :label="$t('payrollO.amount')"
          align="center"
          prop="amount"
          min-width="120" />
        <el-table-column :label="$t('payrollO.transStatus')"
          align="center"
          prop="transStatus"
          :show-overflow-tooltip="true"
          min-width="140">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.trans_status"
              :value="scope.row.transStatus" />
          </template>
        </el-table-column>
        <el-table-column :label="$t('payrollO.transAmount')"
          align="center"
          prop="transAmount"
          :show-overflow-tooltip="true"
          min-width="120" />
        <el-table-column :label="$t('payrollO.payeeNumber')"
          align="center"
          prop="payeeNumber"
          min-width="120"
          show-overflow-tooltip />
        <el-table-column :label="$t('payrollO.transNumber')"
          align="center"
          prop="transNumber"
          min-width="120"
          show-overflow-tooltip />
        <el-table-column :label="$t('payrollO.status')"
          align="center"
          min-width="100">
          <template slot-scope="scope">
            <el-switch v-model="scope.row.status"
              active-value="1"
              inactive-value="0"
              @change="handleStatusChange(scope.row)"></el-switch>
          </template>
        </el-table-column>
        <el-table-column :label="$t('payrollO.auditStatus')"
          align="center"
          prop="auditStatus"
          min-width="120">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.audit_status"
              :value="scope.row.auditStatus" />
          </template>
        </el-table-column>
        <el-table-column :label="$t('common.createBy')"
          align="center"
          prop="createBy"
          min-width="160"
          show-overflow-tooltip />
        <el-table-column :label="$t('common.createTime')"
          align="center"
          prop="createTime"
          min-width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('common.updateBy')"
          align="center"
          prop="updateBy"
          min-width="160"
          show-overflow-tooltip />
        <el-table-column :label="$t('common.updateTime')"
          align="center"
          prop="updateTime"
          min-width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.updateTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('common.remark')"
          prop="remark"
          min-width="160"
          show-overflow-tooltip />
        <el-table-column :label="$t('common.controls')"
          align="center"
          class-name="small-padding fixed-width"
          fixed="right"
          min-width="180">
          <template slot-scope="scope">
            <!-- <el-button size="mini"
              type="text"
              icon="el-icon-document"
              @click="handlePayeeMgt(scope.row)">{{$t('payrollO.payMgt')}}</el-button>
            <el-button size="mini"
              type="text"
              icon="el-icon-view"
              @click="handleView(scope.row)">{{$t('common.view')}}</el-button> -->
            <!-- <el-button size="mini"
              type="text"
              icon="el-icon-check"
              v-if="scope.row.auditStatus == '0' || scope.row.auditStatus == '2'"
              @click="handleUpdateAuditStatus(scope.row)">{{scope.row.auditStatus == '0'?  $t('payrollO.submitAudit'): $t('payrollO.withdrawAudit')}}</el-button>
            <el-button size="mini"
              type="text"
              icon="el-icon-check"
              @click="handleSysAudit(scope.row)">{{$t('payrollO.audit')}}</el-button> -->
            <template v-if="scope.row.auditStatus != '1'">

              <el-button size="mini"
                type="text"
                icon="el-icon-edit"
                v-if="scope.row.auditStatus == '0' || scope.row.auditStatus == '-1'"
                @click="handleUpdate(scope.row)">{{$t('common.edit')}}</el-button>
              <el-button size="mini"
                type="text"
                icon="el-icon-delete"
                v-if="scope.row.auditStatus == '0' || scope.row.auditStatus == '-1'"
                @click="handleDelete(scope.row)">{{$t('common.delete')}}</el-button>

              <el-dropdown size="mini"
                @command="(command) => handleCommand(command, scope.row)">
                <el-button size="mini"
                  type="text"
                  icon="el-icon-d-arrow-right">{{$t('common.more')}}</el-button>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item command="handleView"
                    icon="el-icon-view">{{$t('common.view')}}</el-dropdown-item>

                  <el-dropdown-item command="handlePayeeMgt"
                    icon="el-icon-view">{{$t('payrollO.payMgt')}}</el-dropdown-item>

                  <el-dropdown-item command="handleUpdateAuditStatus"
                    v-if="scope.row.auditStatus == '0' || scope.row.auditStatus == '-1' || scope.row.auditStatus == '2'"
                    icon="el-icon-circle-check">
                    {{(scope.row.auditStatus == '0' || scope.row.auditStatus == '-1')?  $t('payrollO.submitAudit'): $t('payrollO.withdrawAudit')}}
                  </el-dropdown-item>

                  <el-dropdown-item command="handleSysAudit"
                    v-if="scope.row.auditStatus == '2' && userInfo.exchangeId== 0"
                    icon="el-icon-check">{{$t('payrollO.audit')}}</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </template>
            <template v-else>
              <el-button size="mini"
                type="text"
                icon="el-icon-view"
                @click="handleView(scope.row)">{{$t('common.view')}}</el-button>
              <el-button size="mini"
                type="text"
                icon="el-icon-document"
                @click="handlePayeeMgt(scope.row)">{{$t('payrollO.payMgt')}}</el-button>
            </template>
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    </div>

    <!-- 查看详情 -->
    <ViewShow :title="$t('common.viewDetail')"
      :open="showView"
      :dataList="viewList"
      :isLine="true"
      :labelWidth="160"
      width="800"
      @toClose="showView = false" />

    <!-- 添加或修改角色配置对话框 -->
    <el-dialog :title="title"
      :visible.sync="open"
      width="600px"
      append-to-body>
      <el-form ref="form"
        :model="form"
        :rules="rules"
        label-width="140px">
        <el-form-item :label="$t('payrollO.subject')"
          prop="subject">
          <el-input v-model="form.subject"
            maxlength="50"
            :placeholder="$t('common.placeholderContent')" />
        </el-form-item>
        <!-- <el-form-item :label="$t('payrollO.bankName')"
          prop="bankId">
          <el-select v-model="f.bankId"
            filterable
            remote
            reserve-keyword
            :placeholder="$t('common.placeholderSelect')"
            :remote-method="remoteMethod2"
            :loading="bankLoading"
            style="width: 100%">
            <el-option v-for="item in bankList"
              :key="item.bankId"
              :label="item.bankName"
              :value="item.bankId">
            </el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item :label="$t('payrollO.amount')"
          prop="amount">
          <el-input v-model="form.amount"
            maxlength="20"
            disabled
            @input="form.amount = onInput(form.amount)"
            :placeholder="$t('payrollO.autoTocount')">
            <template slot="append">{{$t('common.unit')}}</template>
          </el-input>
        </el-form-item>
        <el-form-item :label="$t('payrollO.priority')"
          prop="priority">
          <!-- <el-input v-model="form.priority"
            maxlength="20"
            :placeholder="$t('common.placeholderContent')" /> -->
          <el-select v-model="form.priority"
            :placeholder="$t('common.placeholderSelect')"
            clearable
            style="width: 100%">
            <el-option v-for="dict in dict.type.md_wage_priority"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value" />
          </el-select>
        </el-form-item>
        <el-form-item :label="$t('payrollO.transDate')"
          prop="transDate">
          <el-date-picker v-model="form.transDate"
            type="datetime"
            :placeholder="$t('common.placeholderSelect')"
            clearable
            style="width: 100%"
            format="yyyy-MM-dd HH:mm:ss"
            value-format="yyyy-MM-dd HH:mm:ss">
          </el-date-picker>
        </el-form-item>
        <!-- <el-form-item :label="$t('payrollO.transType')"
          prop="transType">
          <el-select v-model="form.transType"
            :placeholder="$t('common.placeholderSelect')"
            clearable
            style="width: 100%">
            <el-option v-for="dict in dict.type.trans_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value" />
          </el-select>
        </el-form-item> -->
        <el-form-item :label="$t('payrollO.status')">
          <el-radio-group v-model="form.status">
            <el-radio v-for="dict in dict.type.sys_data_status"
              :key="dict.value"
              :label="dict.value">{{ dict.label }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item :label="$t('payrollO.beneficiarys')"
          v-if="!this.form.batchId">
          <el-button type="primary"
            :icon="form.file? 'el-icon-tickets': ''"
            style="position: relative">
            {{$t('common.upload')}}
            <input id="filePath"
              name="filePath"
              class="filePath"
              type="file"
              accept=".xlsx,.xls"
              @change="toSelectFile">
          </el-button>
        </el-form-item>
        <el-form-item :label="$t('common.remark')">
          <el-input v-model="form.remark"
            type="textarea"
            maxlength="200"
            :placeholder="$t('common.placeholderContent')"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer"
        class="dialog-footer">
        <el-button type="primary"
          @click="submitForm">{{$t('common.ok')}}</el-button>
        <el-button @click="cancel">{{$t('common.cancel')}}</el-button>
      </div>
    </el-dialog>

    <!-- 管理员通过/驳回 -->
    <el-dialog :title="$t('payrollO.adminAudit')"
      :visible.sync="openAdminAudit"
      width="500px"
      append-to-body>
      <el-form ref="formAdminAudit"
        :model="formAdminAudit"
        :rules="rulesAdminAudit"
        label-width="120px">
        <el-form-item :label="$t('payrollO.auditStatus')"
          prop="auditStatus">
          <el-radio-group v-model="formAdminAudit.auditStatus">
            <el-radio key="1"
              label="1">{{ $t('payrollO.pass') }}</el-radio>
            <el-radio key="-1"
              label="-1">{{ $t('payrollO.turnDown') }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item :label="$t('payrollO.auditRemark')"
          prop="auditRemark"
          v-if="formAdminAudit.auditStatus == '-1'">
          <el-input v-model="formAdminAudit.auditRemark"
            type="textarea"
            maxlength="200"
            :placeholder="$t('common.placeholderContent')" />
        </el-form-item>
      </el-form>
      <div slot="footer"
        class="dialog-footer">
        <el-button type="primary"
          @click="submitFormAdminAudit">{{$t('common.ok')}}</el-button>
        <el-button @click="cancelAdminAudit">{{$t('common.cancel')}}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  getBatchList,
  batchDetail,
  addBatch,
  updateBatch,
  delBatch,
  changeBatchStatus,
  updateAuditStatus,
  changeAuditStatus
} from "@/api/transaction/payrollOrder.js";
import {
  getExhUserList,
} from "@/api/system/exchangeUser.js";
import {
  getBankList,
} from "@/api/fundAccount/bankInfo.js";
import ViewShow from '@/views/components/viewShow.vue'
import { onInput } from '@/utils/util.js'
import { mapGetters } from 'vuex'

export default {
  name: "PayrollOrder",
  dicts: ["sys_data_status", "trans_status", "audit_status", "md_wage_priority"],
  components: { ViewShow },
  data () {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 角色表格数据
      batchList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        exchangeId: null,
        subject: null,
        status: null,
        auditStatus: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        subject: [
          { required: true, message: this.$t('common.ruleInputEmpty'), trigger: "blur" },
        ],
        // bankId: [
        //   { required: true, message: this.$t('common.ruleSelectEmpty'), trigger: "change" },
        // ],
        // amount: [
        //   { required: true, message: this.$t('common.ruleInputEmpty'), trigger: "blur" },
        // ],
        priority: [
          { required: true, message: this.$t('common.ruleInputEmpty'), trigger: "blur" },
        ],
        transDate: [
          { required: true, message: this.$t('common.ruleSelectEmpty'), trigger: "change" },
        ],
        transType: [
          { required: true, message: this.$t('common.ruleSelectEmpty'), trigger: "change" },
        ],
      },

      exchangeList: [],
      exhloading: false,
      bankList: [],
      bankLoading: false,
      showView: false,
      viewList: [],

      openAdminAudit: false,
      formAdminAudit: {},
      rulesAdminAudit: {
        auditStatus: [
          { required: true, message: this.$t('common.ruleSelectEmpty'), trigger: "blur" },
        ],
        auditRemark: [
          { required: true, message: this.$t('common.ruleInputEmpty'), trigger: "blur" },
        ],
      }
    };
  },
  computed: {
    ...mapGetters([
      'userInfo',
      'refreshPayrollOrder'
    ]),
  },
  watch: {
    refreshPayrollOrder (val) {
      if (val) {
        this.getList();
        this.$store.dispatch("common/toRefresPayrollPage", '')
      }
    }
  },
  created () {
    this.getList();
    this.$store.dispatch("common/toRefresPayrollPage", '')
  },
  methods: {
    onInput,
    // 更多操作触发
    handleCommand (command, row) {
      switch (command) {
        case "handleView":
          this.handleView(row);
          break;
        case "handlePayeeMgt":
          this.handlePayeeMgt(row);
          break;
        case "handleUpdateAuditStatus":
          this.handleUpdateAuditStatus(row);
          break;
        case "handleSysAudit":
          this.handleSysAudit(row);
          break;
        default:
          break;
      }
    },
    // 搜索汇兑用户
    remoteMethod (query) {
      if (query !== '') {
        this.exhloading = true;
        getExhUserList({
          pageNum: 1,
          pageSize: 10,
          payType: 'payout',
          status: 1,
          exchangeName: query
        }).then(
          (response) => {
            this.exchangeList = response.rows;
            this.exhloading = false;
          }
        );
      } else {
        this.exchangeList = [];
      }
    },
    // 搜索银行
    remoteMethod2 (query) {
      if (query !== '') {
        this.bankLoading = true;
        getBankList({
          pageNum: 1,
          pageSize: 10,
          bankName: query
        }).then(
          (response) => {
            this.bankList = response.rows;
            this.bankLoading = false;
          }
        );
      } else {
        this.bankList = [];
      }
    },
    /** 查询列表 */
    getList () {
      this.loading = true;
      getBatchList(this.queryParams).then(
        (response) => {
          this.batchList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    // 提交审核/撤销审核
    handleUpdateAuditStatus (row) {
      let text = ''
      if (row.auditStatus == '0' || row.auditStatus == '-1') {
        text = this.$t('payrollO.submitAuditTips')
      } else {
        text = this.$t('payrollO.withdrawAuditTips')
      }

      this.$modal
        .confirm(text)
        .then(function () {
          return updateAuditStatus({
            batchId: row.batchId,
            auditStatus: (row.auditStatus == '0' || row.auditStatus == '-1') ? '2' : '0'
          });
        })
        .then(() => {
          this.$modal.msgSuccess(this.$t('common.successfulOperation'));
          this.getList();
        })
        .catch(function () {

        });
    },
    // 管理员审核/驳回
    handleSysAudit (row) {
      this.formAdminAudit = {
        batchId: row.batchId,
        auditStatus: null,
        auditRemark: null,
      }
      this.resetForm("formAdminAudit");
      this.openAdminAudit = true
    },
    submitFormAdminAudit () {
      this.$refs["formAdminAudit"].validate((valid) => {
        if (valid) {
          changeAuditStatus(this.formAdminAudit).then((response) => {
            this.$modal.msgSuccess(this.$t('common.successfulOperation'));
            this.openAdminAudit = false;
            this.getList();
          });
        }
      });
    },
    cancelAdminAudit () {
      this.openAdminAudit = false
    },
    // 工资收款人管理
    handlePayeeMgt (row) {
      const batchId = row.batchId;
      this.$router.push({
        path: "/transaction/payroll-order/payee/" + batchId,
        query: {
          auditStatus: row.auditStatus
        }
      });
    },
    // 查看详情
    handleView (row) {
      this.viewList = []
      batchDetail(row.batchId).then((response) => {
        let statusList = this.dict.type.sys_data_status
        let transStatusList = this.dict.type.trans_status
        let viewInfo = response.data;
        let showData = ['subject', 'exchangeName', 'amount', 'priority', 'transStatus', 'transStartTime', 'transEndTime',
          'transAmount', 'payeeNumber', 'transNumber', 'status']
        let commonData = ['remark', 'createBy', 'createTime', 'updateBy', 'updateTime']

        showData.forEach(item => {
          let value = ''
          if (item == 'transStatus') {
            value = transStatusList.filter(i => viewInfo[item] == i.value)[0].label
          } else if (item == 'status') {
            value = statusList.filter(i => viewInfo[item] == i.value)[0].label
          } else {
            value = viewInfo[item]
          }

          this.viewList.push({
            type: 'text',
            label: this.$t(`payrollO.${item}`) + '：',
            value
          })
        })
        commonData.forEach(item => {
          this.viewList.push({
            type: 'text',
            label: this.$t(`common.${item}`) + '：',
            value: viewInfo[item]
          })
        })

        setTimeout(() => {
          this.showView = true;
        })
      });
    },
    // 状态修改
    handleStatusChange (row) {
      // let text = row.status === "0" ? "启用" : "停用";
      let text = '';
      let tips = ''
      if (row.status === "1") {
        text = `${this.$t('common.statusChangesEnable')} ${row.subject} ?`
        tips = this.$t('common.enabledSuccessfully')
      } else {
        text = `${this.$t('common.statusChangesDisable')} ${row.subject} ?`
        tips = this.$t('common.disableSuccessfully')
      }
      this.$modal
        .confirm(text)
        .then(function () {
          return changeBatchStatus({
            status: row.status,
            batchId: row.batchId
          });
        })
        .then(() => {
          this.$modal.msgSuccess(tips);
        })
        .catch(function () {
          row.status = row.status === "0" ? "1" : "0";
        });
    },
    // 取消按钮
    cancel () {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset () {
      this.form = {
        // bankId: null,
        amount: null,
        subject: null,
        priority: null,
        transDate: null,
        transType: null,
        status: '1',
        remark: '',
        fileName: null,
        file: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.queryParams.exchangeId = null
      this.exchangeList = []
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange (selection) {
      this.ids = selection.map((item) => item.batchId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },

    /** 新增按钮操作 */
    handleAdd () {
      this.reset();
      this.open = true;
      this.title = this.$t('payrollO.addBatch');
    },
    /** 修改按钮操作 */
    handleUpdate (row) {
      this.reset();
      const batchId = row.batchId || this.ids;
      batchDetail(batchId).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = this.$t('payrollO.editBatch');
      });
    },
    toSelectFile (e) {
      let file = e.target.files[0];
      this.form.fileName = file.name
      this.form.file = file
    },
    /** 提交按钮 */
    submitForm: function () {

      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.batchId != undefined) {
            updateBatch(this.form).then((response) => {
              this.$modal.msgSuccess(this.$t('common.editSuccessfully'));
              this.open = false;
              this.getList();
            });
          } else {
            if (!this.form.amount) this.form.amount = 0
            let formData = new FormData();
            for (let key in this.form) {
              formData.append(key, this.form[key])
            }
            addBatch(formData).then((response) => {
              this.$modal.msgSuccess(this.$t('common.newSuccess'));
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete (row) {
      const batchIds = row.batchId || this.ids;
      this.$modal
        .confirm(this.$t('common.deleteDataTips'))
        .then(function () {
          return delBatch(batchIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess(this.$t('common.successfullyDeleted'));
        })
        .catch(() => { });
    },
    // 下载模板
    handleDownload () {
      //herf为本地下载路径，文件在public目录下
      let dom = document.createElement("a");
      dom.href = "/bank_detail.xlsx";
      dom.download = "bank_detail.xlsx";
      document.body.appendChild(dom);
      // 点击下载
      dom.click();
      document.body.removeChild(dom);
    }
  },
};
</script>

<style lang="scss" scoped>
.filePath {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}
</style>
